package com.ruoyi.lm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lm.domain.LmBanner;
import com.ruoyi.lm.service.ILmBannerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页轮播Controller
 * 
 * @author ruoyi
 * @date 2020-09-23
 */
@Controller
@RequestMapping("/lm/banner")
public class LmBannerController extends BaseController
{
    private String prefix = "lm/banner";

    @Autowired
    private ILmBannerService lmBannerService;

    @RequiresPermissions("lm:banner:view")
    @GetMapping()
    public String banner()
    {
        return prefix + "/banner";
    }

    /**
     * 查询首页轮播列表
     */
    @RequiresPermissions("lm:banner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmBanner lmBanner)
    {
        startPage();
        List<LmBanner> list = lmBannerService.selectLmBannerList(lmBanner);
        return getDataTable(list);
    }

    /**
     * 导出首页轮播列表
     */
    @RequiresPermissions("lm:banner:export")
    @Log(title = "首页轮播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LmBanner lmBanner)
    {
        List<LmBanner> list = lmBannerService.selectLmBannerList(lmBanner);
        ExcelUtil<LmBanner> util = new ExcelUtil<LmBanner>(LmBanner.class);
        return util.exportExcel(list, "banner");
    }

    /**
     * 新增首页轮播
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页轮播
     */
    @RequiresPermissions("lm:banner:add")
    @Log(title = "首页轮播", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LmBanner lmBanner)
    {
        return toAjax(lmBannerService.insertLmBanner(lmBanner));
    }

    /**
     * 修改首页轮播
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LmBanner lmBanner = lmBannerService.selectLmBannerById(id);
        mmap.put("lmBanner", lmBanner);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页轮播
     */
    @RequiresPermissions("lm:banner:edit")
    @Log(title = "首页轮播", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LmBanner lmBanner)
    {
        return toAjax(lmBannerService.updateLmBanner(lmBanner));
    }

    /**
     * 删除首页轮播
     */
    @RequiresPermissions("lm:banner:remove")
    @Log(title = "首页轮播", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmBannerService.deleteLmBannerByIds(ids));
    }
}
